package com.wishwall.beans;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonProperty;

@Entity
@Table(name="T_USER")
public class UserBean implements Serializable {


	private static final long serialVersionUID = 5815055706379820788L;

	@Id
	@Column(name="PK_USER_ID")
	private Integer id;

	@Column(name="USERNAME")
	@JsonProperty
	private String username;

	@Column(name="DISPLAY_NAME")
	@JsonProperty
	private String displayName;

	@Column(name="PASSWORD")
	private String password;

	@Column(name="EMAIL")
	@JsonProperty
	private String email;

	@Column(name="LAST_ACTIVE_TIME")
	private Timestamp lastActiveTime;

	@OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL}, orphanRemoval=true)
	@JoinColumn(name="USER_FK")
	@JsonProperty
	private List<UserRoleMappingBean> userRoles = null;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Timestamp getLastActiveTime() {
		return lastActiveTime;
	}

	public void setLastActiveTime(Timestamp lastActiveTime) {
		this.lastActiveTime = lastActiveTime;
	}

	public List<UserRoleMappingBean> getUserRoles() {
		return userRoles;
	}

	public void setUserRoles(List<UserRoleMappingBean> rolesMapping) {
		this.userRoles = rolesMapping;
	}

	@Override
	public int hashCode() {
		if (this.id != null) {
			return this.id.hashCode();
		} else {
			return super.hashCode();
		}
	}

	@Override
	public boolean equals(Object obj) {

		if (obj == null) {
			return false;
		}

		if(this == obj) {
			return true;
		}

		if (!(obj instanceof UserBean)) {
			return false;
		}

		if (this == obj) {
			return true;
		}

		UserBean other = (UserBean) obj;
		if ((id == null) || (other.getId() == null)) {
			return false;
		}

		return (id.equals(other.getId()));
	}

}
